package com.simulation;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.reflect.TypeToken;
import com.lambdaworks.redis.*;
import com.lambdaworks.redis.api.async.RedisAsyncCommands;
import com.lambdaworks.redis.api.sync.RedisCommands;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/* 
{
	"id": 12345,
	"body": {
		"weight": 60,
		"height": 170,
		"gender": 0
	} ,
	"clothing": [
		{
			"material": 1,
			"thickness": 2,
			"type": 0
		} ,
		{
			"material": 1,
			"thickness": 2,
			"type": 3
		}
	] ,
	"env": [26, 45],
	"status": [
		{
			"speed": 5,
			"time": 20
		} ,
		{
			"speed": 3,
			"time": 30
		}
	]
}
*/
/* test data:
 * {"clothing":[{"material":0,"thickness":0.04,"type":1},{"material":0,"thickness":0.04,"type":4}],"id":"12345","body":{"gender":0,"weight":60,"height":170},"env":[28,50],"status":[{"time":30,"speed":5},{"time":30,"speed":3}]}
 */
@RestController
@RequestMapping("/api")
public class Main {

	//static private SimulateData simulateData;
	//static private int temperature;
	//static private int humidity;
	
	@RequestMapping("/boom")
	public String test() {
		return "Connected!";
	}
	
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String loginRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="password", required=true) String pwd) {
		String responseString = requestLogin(id, pwd);
		return responseString;
	}
	
	private String requestLogin(String id, String pwd) {
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		String realPwd = commands.get("user:"+id+":password");
		
		if(pwd.equals(realPwd)) {
			Gson gson = new Gson();
			Map<String,String> info = commands.hgetall("user:"+id+":info");
			client.shutdown();
			return gson.toJson(info);
		}
		else {
			client.shutdown();
			return "failed";
		}
	}
	
	@RequestMapping(value = "/reg", method = RequestMethod.POST)
	public String registerRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="password", required=true) String pwd) {
		String responseString = requestRegister(id, pwd);
		return responseString;
	}
	
	private String requestRegister(String id, String pwd) {
		String pass_key = "user:"+id+":password";
		String info_key = "user:"+id+":info";
		String record_key = "user:"+id+":records";
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		if(commands.exists(pass_key, info_key, record_key) != 0) return "failed";
		// set default info
		Map<String, String> infomap = new HashMap<String, String>();
		infomap.put("name", "user"+id);
		infomap.put("height", "170");
		infomap.put("weight", "60");
		infomap.put("gender", "0");

		commands.watch(pass_key, info_key);
		commands.multi();
		commands.set(pass_key, pwd);
		commands.hmset(info_key, infomap);
		List<Object> result = commands.exec();
		client.shutdown();

		if(result==null) return "failed";
		String resultString = new Gson().toJson(result);
		return resultString;
	}
	
	@RequestMapping(value = "/uu", method = RequestMethod.POST)
	public String updateUserRequest(@RequestParam(value="info", required=true) String info) {
		Map<String,String> infoMap = new Gson().fromJson(info, new TypeToken<Map<String,String>>(){}.getType());
		String id = infoMap.remove("id");
		String responseString = "failed";
		if(id==null) return "no id";
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		if(commands.hlen("user:"+id+":info")!=0) {
			responseString = commands.hmset("user:"+id+":info", infoMap);
		}
		client.shutdown();
		return responseString;
	}
	
	@RequestMapping(value = "/gc", method = RequestMethod.GET)
	public String getClothesRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="nextItem", required=true) int nextItem) {
		String responseString = "failed";
		final int offset = 9;
		final String clothes_set_key = "user:"+id+":all_clothes";
		List<Map<String,String>> all_items = new ArrayList<>();
		Map<String,Object> result = new HashMap<>();
		
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		List<String> names = commands.zrange(clothes_set_key, nextItem, nextItem+offset);
		for(String name : names) {
			Map<String,String> item = commands.hgetall("clothes:"+id+":"+name);
			item.put("title", name);
			all_items.add(item);
		}
		client.shutdown();
		result.put("nextItem", nextItem+names.size());
		result.put("items", all_items);
		responseString = new Gson().toJson(result);
		return responseString;
	}
	
	@RequestMapping(value = "/ac", method = RequestMethod.POST)
	public String addClothesRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="info", required=true) String info) {
		Map<String,String> clothes = null;
		try{
			clothes = new Gson().fromJson(info, new TypeToken<Map<String,String>>(){}.getType());
		} catch(Exception e) {
			e.printStackTrace();
			return "-1";
		}
		String name = clothes.remove("title");
		if(id==null || name==null) return "-1";// error: incomplete info
		id = id.trim();
		name = name.trim();
		if(id.isEmpty() || name.isEmpty()) return "-1";
		
		// check if clothes name already exists in the set
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		if(commands.zscore("user:"+id+":all_clothes", name)!=null) {
			client.shutdown();
			return "-2";// error: name already exists
		}
		
		// add the hash key
		int score = name.charAt(0)-'a';
		String all_clothes = "user:"+id+":all_clothes";
		String clothes_hash = "clothes:"+id+":"+name;
		commands.watch(clothes_hash);
		commands.multi();
		commands.zadd(all_clothes, score, name);
		commands.hmset(clothes_hash, clothes);
		List<Object> responseString = commands.exec();
		client.shutdown();
		if(responseString==null) return "-3";// error: fail to add new clothes
		return responseString.get(1).toString();
	}
	
	@RequestMapping(value = "/uc", method = RequestMethod.POST)
	public String updateClothesRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="info", required=true) String info) {
		Map<String,String> clothes = null;
		try{
			clothes = new Gson().fromJson(info, new TypeToken<Map<String,String>>(){}.getType());
		} catch(Exception e) {
			e.printStackTrace();
			return "-1";
		}
		String name = clothes.remove("title");
		if(id==null || name==null) return "-1";// error: incomplete info
		id = id.trim();
		name = name.trim();
		if(id.isEmpty() || name.isEmpty()) return "-1";
		
		// check if clothes name already exists in the set
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		if(commands.zscore("user:"+id+":all_clothes", name)==null) {
			client.shutdown();
			return "-2";// error: name doesn't exist
		}
		
		// update the hash key
		String responseString = commands.hmset("clothes:"+id+":"+name, clothes);
		client.shutdown();
		return responseString;
	}
	
	@RequestMapping(value = "/dc", method = RequestMethod.POST)
	public String deleteClothesRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="name", required=true) String name) {
		if(id==null || name==null) return "1";// error: null params
		id = id.trim();
		name = name.trim();
		if(id.isEmpty() || name.isEmpty()) return "1";
		
		// check if clothes name already exists in the set
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		if(commands.zscore("user:"+id+":all_clothes", name)==null) {
			client.shutdown();
			return "2";// error: name doesn't exist
		}
		
		// remove the clothes
		String all_clothes = "user:"+id+":all_clothes";
		String clothes_hash = "clothes:"+id+":"+name;
		commands.multi();
		commands.zrem(all_clothes, name);
		commands.del(clothes_hash);
		List<Object> responseString = commands.exec();
		client.shutdown();
		return responseString.toString();
	}
	
	@RequestMapping(value = "/dmc", method = RequestMethod.POST)
	public String deleteMultipleClothesRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="name", required=true) String name) {
		if(id==null || name==null) return "-1";
		String prefix = "clothes:"+id+":";
		String[] multipleNames = new Gson().fromJson(name, String[].class);
		String[] multipleKeys = new String[multipleNames.length];
		for(int i=0; i<multipleKeys.length; i++) {
			multipleKeys[i] = prefix+multipleNames[i];
		}
		
		String all_clothes = "user:"+id+":all_clothes";
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisCommands<String, String> commands = client.connect().sync();
		commands.multi();
		commands.zrem(all_clothes, multipleNames);
		commands.del(multipleKeys);
		List<Object> responseString = commands.exec();
		client.shutdown();
		return responseString.toString();
	}
	
	@RequestMapping(value = "/sim", method = RequestMethod.POST)
	public String simRequest(@RequestParam(value="id", required=true) String id,
			@RequestParam(value="params", required=true) String params) throws Exception{
		System.out.println(params);
		Gson gson = new Gson();
		Map<String, JsonElement> paramsMap = gson.fromJson(params, new TypeToken<Map<String,JsonElement>>(){}.getType());
		// initialize test data
		/*JSONObject json = new JSONObject();
    	json.put("id", "13922746309");    	
    	JSONObject body = new JSONObject();
    	body.put("weight", 60).put("height", 170).put("gender", 0); 	
    	JSONArray clothing = new JSONArray();
    	clothing.put(new JSONObject().put("material", 0).put("thickness",0.04).put("type", 1));
    	clothing.put(new JSONObject().put("material", 0).put("thickness",0.04).put("type", 4));	
    	JSONArray env = new JSONArray().put(30).put(50);   	
    	JSONArray status = new JSONArray();
    	status.put(new JSONObject().put("speed", 5).put("time",30));
    	status.put(new JSONObject().put("speed", 3).put("time",30));  	
    	json.put("body",body).put("clothing", clothing).put("env", env).put("status", status);*/
    	// end initialize test data
    	
		SimulateData simulateData = new SimulateData();
		init(simulateData, paramsMap);
		simulateData.data_coming_flag = true;
		simulateData.HumanSimulation();
		
		//保存仿真记录到数据库
		String record_key = "user:"+id+":records";
		paramsMap.remove("user");
		paramsMap.put("records", simulateData.records);
		paramsMap.put("time", new JsonPrimitive(new SimpleDateFormat("yyyyMMdd-HH:mm:ss").format(new Date())));
		String record_val = gson.toJson(paramsMap);
		
		RedisClient client = RedisClient.create("redis://localhost:6379");
		RedisAsyncCommands<String, String> commands = client.connect().async();
		commands.lpush(record_key, record_val);
		commands.ltrim(record_key, 0, 4);//每个用户最多保存五条记录
		client.shutdown();
		
		System.out.println(record_val);
		return record_val;
	}
	
	private void init(SimulateData simulateData, Map<String,JsonElement> paramsMap) throws Exception{
		simulateData.DefaultFiber();//定义默认纤维
		JsonArray clothings = paramsMap.get("clothes").getAsJsonArray();
		JsonArray status = paramsMap.get("stages").getAsJsonArray();
		JsonObject userMap = paramsMap.get("user").getAsJsonObject();
		JsonObject envMap = paramsMap.get("env").getAsJsonObject();
		
		String ID = userMap.getAsJsonPrimitive("id").getAsString();
		int temperature = envMap.getAsJsonPrimitive("temperature").getAsInt();
		int humidity = envMap.getAsJsonPrimitive("humidity").getAsInt();
    	
    	// 根据用户参数设置运动阶段
    	for(int i=0; i<status.size(); i++) {
    		JsonObject statu = status.get(i).getAsJsonObject();
    		StageType stage = new StageType();
    		stage.StageName = "Activity"+i;
    		stage.Time = statu.getAsJsonPrimitive("duration").getAsDouble()/100.0;//阶段时长，用户输入是以分钟为单位，例如20min这里会转化为0.2
    		stage.OutTemperatrue = temperature + 273.16;//外界温度
    		stage.OutRH = humidity/100.0;//外界湿度
    		//---运动量大小，这里要修改---
    		stage.Work = 58.2;
    		//------------------------
    		simulateData.m_stageList.add(stage);
    		
    		//设置边界条件
    		BoundarySeg[] boundary = new BoundarySeg[6];
    		for(int j=0; j<6; j++) {
				boundary[j] = new BoundarySeg();
				//---人体代谢率，这里要修改---
				boundary[j].m_BHuman.m_metabolicRate = 58;
				//------------------------
				boundary[j].m_stageName = stage.StageName;
				boundary[j].m_segment = j;
				simulateData.m_boundarySeg[j].add(boundary[j]);
			}
    		//boundary[1].m_Bfabric.add(new BoundaryFabric());
    		//boundary[2].m_Bfabric.add(new BoundaryFabric());
    		//boundary[4].m_Bfabric.add(new BoundaryFabric());
    	}
    	
    	// 织物设置
    	GarmentParts garmentparts = new GarmentParts();//记录各身体部分上覆盖的衣物属性，主要是覆盖率和衣物名
    	final double[] thicknessArray = {0.02, 0.04, 0.06};//服装的厚度，分为对应薄、中、厚
    	for(int i=0; i<6; i++) {
    		GarmentType garment = new GarmentType();
    		garment.GarmentName = "Garment"+i;
    		simulateData.m_oringinalGarmentList.add(garment);//经过循环后，原始衣物列表有6个元素，分别对应6个身体部位的服装
    		garmentparts.garmentName[i] = garment.GarmentName;//garmentparts的衣物名与原始衣物列表中的元素绑定
    	}
    	for(int i=0; i<clothings.size(); i++) {
    		JsonObject clothing = clothings.get(i).getAsJsonObject();
    		//根据用户参数设置织物的厚度、材质
    		FabricType fabric = new FabricType();
    		fabric.FabricName = "Fabric"+i;
    		fabric.Thickness = thicknessArray[clothing.getAsJsonPrimitive("thickness").getAsInt()];
    		fabric.FiberList.add(simulateData.m_fiberList.get(clothing.getAsJsonPrimitive("material").getAsInt()));
			fabric.MassRatio.add(100.0);
    		simulateData.m_fabricList.add(fabric);//把织物添加到织物列表中
    		
    		//根据衣物的款式设置各身体部分的覆盖率
    		int type = clothing.getAsJsonPrimitive("type").getAsInt();
    		switch(type) {
    		case 0:
    			simulateData.GetGarment("Garment1").FabricList.add(i);//向原始衣物列表中对应的身体部位添加织物
    			garmentparts.coverRatio[1] = 1.0;
    			break;
    		case 1:
    			simulateData.GetGarment("Garment1").FabricList.add(i);
    			simulateData.GetGarment("Garment2").FabricList.add(i);
    			garmentparts.coverRatio[1] = 1.0;
    			garmentparts.coverRatio[2] = 0.5;
    			break;
    		case 2:
    			simulateData.GetGarment("Garment1").FabricList.add(i);
    			simulateData.GetGarment("Garment2").FabricList.add(i);
    			garmentparts.coverRatio[1] = 1.0;
    			garmentparts.coverRatio[2] = 1.0;
    			break;
    		case 3:
    			simulateData.GetGarment("Garment4").FabricList.add(i);
    			garmentparts.coverRatio[4] = 0.3;
    			break;
    		case 4:
    			simulateData.GetGarment("Garment4").FabricList.add(i);
    			garmentparts.coverRatio[4] = 0.5;
    			break;
    		case 5:
    			simulateData.GetGarment("Garment4").FabricList.add(i);
    			garmentparts.coverRatio[4] = 1.0;
    			break;
    		}
    	}
    	simulateData.m_garmentRecords.add(garmentparts);//正常情况下，m_garmentRecords的大小为1,即只保存一份garmentparts
    	
    	//---从xml文件中读取仿真默认配置，这是通用操作，可以提取出来作为公共代码---
		try {
			simulateData.LoadXML("src"+File.separator+"main"+File.separator+"resources"+File.separator+"default.xml");
		} catch (Exception e) {
			e.printStackTrace();
		}
		//-------------------------------------------------------------
		
		/*for (int i = 0; i < simulateData.m_stageList.size(); i++)
		{
			simulateData.m_stageList.get(i).OutTemperatrue = temperature + 273.16;
			simulateData.m_stageList.get(i).OutRH = humidity/100.0;
			simulateData.m_stageList.get(i).OutVelocity = 0.1;
			simulateData.m_stageList.get(i).Time = 0.288;// ???
			simulateData.m_stageList.get(i).Work = 58.2;
			simulateData.m_stageList.get(i).InVelocity = 3.5;
			simulateData.m_stageList.get(i).InRH = 50;
			simulateData.m_stageList.get(i).InTemperature = 30;
		}*/
		/*for (int i = 0; i < 6; i++){
			for (int j = 0; j < simulateData.m_stageList.size(); j++){
				simulateData.m_boundarySeg[i].get(j).m_BHuman.m_metabolicRate = (int)58.2;
				simulateData.m_boundarySeg[i].get(j).m_BEnv.m_velocity = 3.5;
				simulateData.m_boundarySeg[i].get(j).m_BEnv.m_humidity = 50;
				simulateData.m_boundarySeg[i].get(j).m_BEnv.m_temperature = 30;
			}	
		}*/		
		
		UpdateGarment(simulateData);

		//初始化控制参数
		double m_dTimeStep = 0.01;
		int m_iSaveFequency = 1;
		int m_iFabricGrid = 5;
		int m_iFiberGrid = 8;
		double m_dInitalT = 20;
		double m_dInitalRH = 65;
		double m_dInitalWater = 0.001;
		double m_dInitalP = 101325;
		double m_dInitalVirus = 1E-10;
		simulateData.m_controls.TimeStep = m_dTimeStep;
		simulateData.m_controls.SaveFrequency = m_iSaveFequency;
		simulateData.m_controls.FabricGrid = m_iFabricGrid;
		simulateData.m_controls.FiberGrid = m_iFiberGrid;
		simulateData.m_controls.InitialT = m_dInitalT + 273.16;
		simulateData.m_controls.InitialRH = m_dInitalRH / 100;
		simulateData.m_controls.InitialWater = m_dInitalWater;
		simulateData.m_controls.InitialP = m_dInitalP;
		simulateData.m_controls.VirusInitial = m_dInitalVirus;

		File dir = new File("./datafolder_"+ID);
		if(!dir.exists()) dir.mkdir();
		simulateData.m_fileDir = dir.getPath();//设置仿真记录文件的输出位置
	}

	private void UpdateGarment(SimulateData simulateData) {
		for (int j = 0; j<simulateData.m_stageList.size(); ++j)
		{
			StageType theIterator = simulateData.m_stageList.get(j);
			//将每个运动阶段的各身体部位服装先置为空
			for (int i = 0; i<6; i++)
			{
				theIterator.BodyGarment[i] = -1;
			}
		}
		
		if (simulateData.m_oringinalGarmentList.size()>0)
		{
			//将覆盖在相同身体部位上的服装名连起来，如下面形式：
			//{"garment1;garment2;","garment1;","garment1;","garment1;garment2;","garment1;","garment2;","garment2;"}
			//如果按照前面的流程，得到的结果应该是{"garment0;","garment1;","garment2;","garment3;","garment4;","garment5;"}
			ArrayList<String> names = new ArrayList<>();
			for (int k = 0; k<6; k++)
			{
				StringBuffer name = new StringBuffer();
				for (int i = 0; i<simulateData.m_garmentRecords.size(); ++i)
				{
					GarmentParts theIterator = simulateData.m_garmentRecords.get(i);
					if (theIterator.coverRatio[k]>0) name.append(theIterator.garmentName[k]).append(";");
					else theIterator.garmentName[k] = "";
				}
				names.add(name.toString());//经过循环后，names应有6个元素，分别对应6个身体部位上覆盖的服装名
			}

			simulateData.m_garmentList.clear();
			for (int i = 0; i<names.size(); i++)
			{
				if (names.get(i).isEmpty()) continue;
				boolean flag = false;
				for (int j = 0; j < i; j++)
				{
					//如果当前身体部位上覆盖的服装与之前已经处理过的某个部位相同，可以快速拷贝，节省时间
					if (names.get(i).equals(names.get(j)))
					{
						for (int t = 0; t<simulateData.m_stageList.size(); ++t)
						{
							StageType theIterator = simulateData.m_stageList.get(t);
							theIterator.BodyGarment[i] = theIterator.BodyGarment[j];
							
							for (int k = 0; k<simulateData.m_garmentList.get(theIterator.BodyGarment[i]).FabricList.size() + 1; k++)
							{
								theIterator.SpaceLength[i].add(0.1);
							}
						}
						flag = true;
						break;
					}
				}
				if (flag) continue;

				GarmentType pNewGarment = new GarmentType();
				pNewGarment.GarmentName = "NewGarment"+i;
				pNewGarment.FabricList = new ArrayList<Integer>();

				String tmpStr = names.get(i);
				String[] sp = tmpStr.split(";");//重新将身体部位对应的服装名分割
				for(int n=0; n<sp.length; n++)
				{
					GarmentType pGarment = simulateData.GetGarment(sp[n]);//pGarment是从原始衣物列表中取出来的
					//将pGarment的属性拷贝到pNewGarment
					if (pGarment != null)
					{
						pNewGarment.modelFlag = pGarment.modelFlag;
						pNewGarment.Virus = pGarment.Virus;
						pNewGarment.Liquid = pGarment.Liquid;
						pNewGarment.Gas = pGarment.Gas;
						pNewGarment.SelfHeat = pGarment.SelfHeat;
						pNewGarment.sourceItem = pGarment.sourceItem;
						//pNewGarment.fabricname = pGarment.fabricname;

						//如果一个身体部位上覆盖有多件服装，这些服装包含的织物会被累积添加到pNewGarment的织物列表中
						for (int k = 0; k<pGarment.FabricList.size(); ++k)
							pNewGarment.FabricList.add(pGarment.FabricList.get(k));
					}

				}
				simulateData.m_garmentList.add(pNewGarment);//将pNewGarment添加到最终衣物列表中

				//为各个运动阶段设置最终的服装，实际上所有阶段都是穿相同的服装
				for (int j = 0; j<simulateData.m_stageList.size(); ++j)
				{
					StageType theIterator = simulateData.m_stageList.get(j);
					theIterator.BodyGarment[i] = simulateData.m_garmentList.size() - 1;
					for (int k = 0; k<pNewGarment.FabricList.size(); k++)
					{
						theIterator.SpaceLength[i].add(0.1);
					}
					theIterator.SpaceLength[i].add(0.1);
				}
			}
		}

		for (int i = 0; i<simulateData.m_garmentRecords.size(); ++i)
		{
			GarmentParts garment = simulateData.m_garmentRecords.get(i);
			for (int j = 0; j<6; ++j)
			{
				for (int loop = 0; loop<simulateData.m_stageList.size(); ++loop)
				{
					if (garment.garmentName[j].length() != 0)
					{
						simulateData.m_boundarySeg[j].get(loop).m_Bfabric.clear();
						GarmentType pG = simulateData.GetGarment(garment.garmentName[j]);
						//根据从原始衣物列表中取出的服装设置织物的边界值，维度有两个：运动阶段和身体部位
						for (int k = 0; k<pG.FabricList.size(); ++k)
						{
							BoundaryFabric fabric1 = new BoundaryFabric();
							fabric1.m_indexFabric = pG.FabricList.get(k);
							fabric1.m_heatCoeInner = 13.7;
							fabric1.m_heatCoeOuter = 13.7;
							fabric1.m_massCoeInner = 0.019359;
							fabric1.m_massCoeOuter = 0.019359;
							fabric1.m_evapCoe = 13.7;
							fabric1.m_iMassPumpingRation = 0;
							fabric1.m_iHeatPumpingRation = 0;
							simulateData.m_boundarySeg[j].get(loop).m_Bfabric.add(fabric1);
							//m_listFabric.InsertColumn(iFabric++, simulateData.m_fabricList[pG.FabricList[k]].FabricName, LVCFMT_RIGHT, 350);
						}
					}
				}
			}
		}
	}
}
